package api

import (
	"github.com/gin-gonic/gin"
	jwt "github.com/golangblogs/gojwt"
	"yk/api/handler"
	"yk/api/middleware"
	"yk/consts"
)

func LoadRouter(r *gin.Engine) {
	r.Use(middleware.CQRS())
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register)

		}
		video := api.Group("/video")
		{
			video.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			video.POST("/add", handler.AddVideo)
			video.GET("/examine", handler.Examine)
			video.GET("/info", handler.InfoVideo)
			video.POST("/update", handler.UpdateVideo)
			video.GET("/list", handler.ListVideo)
			video.POST("/del", handler.DelVideo)
		}
		chat := api.Group("/chat")
		{
			chat.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			chat.GET("/ws", handler.Chat)
		}
		admin := api.Group("/admin")
		{
			admin.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			admin.POST("/admin", handler.AdminMessage)
		}
		course := api.Group("/course")
		{
			//course.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			course.POST("/addCourse", handler.AddCourse)
			course.GET("/listCourse", handler.ListCourse)
			course.GET("/infoCourse", handler.InfoCourse)

		}
		barrage := api.Group("/barrage")
		{
			barrage.Use(jwt.JWTAuth(consts.JWT_SECRET_KEY))
			barrage.POST("/addBarrage", handler.AddBarrage)
		}
	}

}
